<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %><%--
  Created by IntelliJ IDEA.
  User: 86177
  Date: 2023/6/27
  Time: 21:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%!
        String url=null;
        String username=null;
        String password=null;
        Connection conn=null;
        Statement std=null;
        ResultSet resultSet=null;
        String sql=null;
        String id=null;
    %>
    <%
    try {
      Class.forName("com.mysql.jdbc.Driver");
      url="jdbc:mysql://localhost:3306/library";
      username="root";
      password="20030607";
      sql="select * from announcement";
      conn= DriverManager.getConnection(url,username,password);
      std=conn.createStatement();
      resultSet= std.executeQuery(sql);
    }catch (Exception e){
      out.print(e);
      e.printStackTrace();
    }
  %><!--连接数据库的基本操作-->
    <style>
        .head{
            border: 1px #00ffff solid;
            text-align: center;
            align-content: center;
            margin: 0 auto;
        }
        .head a{
            background-color: #f2403a;
            color: black;
            cursor: pointer;
        }
    </style>
</head>
<body>
<table class="head" border="1px">
    <tr>
        <th>标题</th>
        <th>内容</th>
        <th>时间</th>
    </tr>
    <%try {
        while (resultSet.next()) {
            out.print("<tr>");
            out.print("<td>" + resultSet.getString("announcement_title") + "</td>");
            out.print("<td>" + resultSet.getString("content") + "</td>");
            out.print("<td>" + resultSet.getTimestamp("time") + "</td>" );
            out.print("<td><a href="+"AnnDelet?id="+resultSet.getInt("announcement_num")+">删除</a></td></tr>");
        }
        resultSet.close();
        std.close();
        conn.close();
    }catch (Exception e){
        e.printStackTrace();
    }
    %>
</table>
</body>
</html>
